package com.songlanyun.modules.marketing.groupbuy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.songlanyun.modules.goods.entity.GoodsSku;
import com.songlanyun.modules.goods.model.vo.ActivitySkuComItemVo;
import com.songlanyun.modules.goods.model.vo.SkuComItemVo;
import com.songlanyun.modules.marketing.groupbuy.entity.GroupBuyActivityGoods;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.Query;

import com.songlanyun.modules.marketing.groupbuy.dao.GroupBuyGoodsSkuDao;
import com.songlanyun.modules.marketing.groupbuy.entity.GroupBuyGoodsSku;
import com.songlanyun.modules.marketing.groupbuy.service.GroupBuyGoodsSkuService;


@Service("groupBuyGoodsSkuService")
public class GroupBuyGoodsSkuServiceImpl extends ServiceImpl<GroupBuyGoodsSkuDao, GroupBuyGoodsSku> implements GroupBuyGoodsSkuService {


    @Override
    public void deleteByGroupBuyGoodsId(Long groupBuyGoodsId) {
        this.baseMapper.delete(
                new LambdaQueryWrapper<GroupBuyGoodsSku>()
                        .eq(GroupBuyGoodsSku::getGroupBuyGoodsId, groupBuyGoodsId)
        );
    }

    @Override
    public List<GroupBuyGoodsSku> getByGroupBuyGoodsId(Long groupBuyGoodsid) {
        return this.baseMapper.selectList(
                new LambdaQueryWrapper<GroupBuyGoodsSku>()
                        .eq(GroupBuyGoodsSku::getGroupBuyGoodsId, groupBuyGoodsid)
        );
    }

    @Override
    public GroupBuyGoodsSku getByGroupBuyGoodsAndSkuHashCode(Long groupBuyGoodsId, String skuHashCode) {
        GroupBuyGoodsSku sku = this.getOne(new LambdaQueryWrapper<GroupBuyGoodsSku>()
                .eq(GroupBuyGoodsSku::getGroupBuyGoodsId, groupBuyGoodsId)
                .eq(GroupBuyGoodsSku::getSkuHashCode, skuHashCode)
                .last("limit 1")
        );
        return sku;
    }

    @Override
    public List<ActivitySkuComItemVo> loadSkuItemList(Long id) {
        return this.baseMapper.loadSkuItemList(id);
    }

    @Override
    public List<GroupBuyGoodsSku> listByGoodIds(Long groupBuyGoodsId) {
        return this.baseMapper.selectList(
                new LambdaQueryWrapper<GroupBuyGoodsSku>()
                        .eq(GroupBuyGoodsSku::getGroupBuyGoodsId, groupBuyGoodsId)
                        .orderByAsc(GroupBuyGoodsSku::getCreateTime)
        );
    }


}
